// pages/channel/memberManage/memberManage.js
var app = getApp();
var _PAGESIZE = 10;//默认页量
var _PAGE = 1;//默认页码
var load= true;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    user_id: '',
    dataList: [],
    hasMore: false, //数据是否加载完成
    loading: false,
    load_show: false,//整体加一个开关 加载
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      user_id: options.user_id
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    _PAGE = 1;
    this.getList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    var that = this;
    var hasMore = that.data.hasMore;
    if (!hasMore) {
      return false;
    }
    that.setData({
      loading: true
    })
    _PAGE++;
    that.getList();
  },

  // 获取列表
  getList() {
    var that = this;
    var user_id = that.data.user_id;
    app.ajax({
      url: 'User/Channel/getPromoterList',
      method: "POST",
      load: load,
      data: {
        user_id: user_id,
        page: _PAGE,
        pageSize: _PAGESIZE
      },
      success: function (res) {
        wx.hideLoading();
        if (res.data.code == 1000) {
          if (_PAGE == 1) {
            that.setData({
              dataList: res.data.data.data,
              empty: false
            });
          } else {
            that.setData({
              dataList: that.data.dataList.concat(res.data.data.data),
              empty: false
            });
          }
          var hasMore = true;
          if (res.data.data.data.length < _PAGESIZE) {
            hasMore = false;
          }
          that.setData({
            hasMore: hasMore,
            loading: false
          });
          load= false;
        }  else {
          if (_PAGE == 1) {
            that.setData({
              hasMore: false,
              loading: false,
              empty: true
            })
          } else {
            that.setData({
              hasMore: false,
              loading: false,
              empty: false
            })
          }
        }
        that.setData({
          load_show: true
        })
      }
    })
  },
})